home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_ll3.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  11.8 KB  |  383 lines

  1. %    Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_ll3.ps 8962 2008-08-11 14:16:18Z ken $
  14. % Initialization file for PostScript LanguageLevel 3 functions.
  15. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  16. % These definitions go into ll3dict or various ProcSets.
  17. % NOTE: the interpreter creates ll3dict.
  18.  
  19. ll3dict begin
  20.  
  21. % We need LanguageLevel 2 or higher in order to have setuserparams and
  22. % defineresource.
  23. languagelevel dup 2 .max .setlanguagelevel
  24.  
  25. % ------ Idiom recognition ------ %
  26.  
  27. /IdiomRecognition false .definepsuserparam
  28.  
  29. % Modify `bind' to apply idiom recognition afterwards.
  30. /.bindscratch 128 string def
  31. % Note that since this definition of `bind' may get bound in,
  32. % it has to function properly even at lower language levels,
  33. % where IdiomRecognition may not be defined.
  34. /.bind_ {        % <proc> .bind <proc'>
  35.   //.bind currentuserparams /IdiomRecognition
  36.   .knownget not { false } if {
  37.     (*) {
  38.       /IdiomSet findresource
  39.       false exch {
  40.         % Stack: proc false dummykey [template substitute]
  41.     exch pop dup 1 get exch 0 get
  42.         % Stack: proc false substitute template
  43.     3 index .eqproc {
  44.       2 index gcheck 1 index gcheck not and {
  45.         pop
  46.       } {
  47.         3 -1 roll pop exch not exit
  48.       } ifelse
  49.     } {
  50.       pop
  51.     } ifelse
  52.       } forall { exit } if
  53.     } //.bindscratch /IdiomSet resourceforall
  54.   } if
  55. } def
  56. /.bind /.bind_ load odef    % note that .bind_ will get bound
  57. currentdict /.bindscratch .undef
  58.  
  59. DELAYBIND NOBIND or not { 
  60. % We can't just do
  61. %   /bind /.bind load def
  62. % because then /bind load == prints --.bind-- .
  63.   /bind {//.bind_ exec} odef
  64. } if
  65. currentdict /.bind_ undef
  66.  
  67. % ------ HalftoneTypes 6, 10, 16 and HalftoneMode ------ %
  68.  
  69. % This code depends on an internal HalftoneType 7 with the following keys:
  70. %    Width, Height, Width2, Height2, TransferFunction:
  71. %      as for HalftoneType 16.
  72. %    Thresholds: a string or bytestring holding the thresholds,
  73. %      (Width x Height + Width2 x Height2) x BitsPerSample / 8 bytes,
  74. %      as for HalftoneType 16 except that the samples may be either
  75. %      8 or 16 bits wide.
  76. %    BitsPerSample: 8 or 16.
  77.  
  78. % Note that this HalftoneType never appears in halftone dictionaries given
  79. % to sethalftone, only as a component in those given to .sethalftone5,
  80. % so its numeric value can be chosen ad lib as long as it differs from the
  81. % other values that are legal in component dictionaries for .sethalftone5
  82. % (currently only 1 and 3).
  83.  
  84. /.makehalftone7 {    % <dict> <dict> <source> <Width> <Height>
  85.             %   (<Width2> <Height2> | null) <BPS> .makehalftone7
  86.             %   <setdict> <dict5> { .sethalftone5 }
  87.   8 dict begin
  88.   /HalftoneType 7 def
  89.   /BitsPerSample exch def
  90.   dup null eq {
  91.     pop 0
  92.   } {
  93.     /Height2 1 index def /Width2 2 index def mul
  94.   } ifelse 3 1 roll
  95.   /Height 1 index def
  96.   /Width 2 index def
  97.   mul add BitsPerSample 8 idiv mul .bigstring
  98.         % Stack: dict dict source str
  99.   dup type /stringtype eq { readstring } { .readbytestring } ifelse
  100.   not { /sethalftone .systemvar /rangecheck signalerror exit } if
  101.   readonly /Thresholds exch def
  102.   /TransferFunction .knownget { /TransferFunction exch def } if
  103.         % If the original Thresholds was a file, replace it with
  104.         % a new one.
  105.   dup /Thresholds get type /filetype eq {
  106.     dup /Thresholds [ Thresholds ] cvx 0 () .subfiledecode put
  107.   } if
  108.   mark /HalftoneType 5 /Default currentdict end .dicttomark
  109.   { .sethalftone5 }
  110. } bind def
  111.  
  112. /.bigstring {    % <size> .bigstring <string|bytestring>
  113.   dup 65400 gt { .bytestring } { string } ifelse
  114. } bind def
  115.  
  116. /.readbytestring {    % <source> <bytestring> .readbytestring
  117.             %   <bytestring> <filled>
  118.         % Note that since bytestrings don't implement getinterval,
  119.         % if filled is false, there is no way to tell how much
  120.         % was read.
  121.   true exch 0 1 2 index length 1 sub {
  122.         % Stack: source true str index
  123.     3 index read not { pop exch not exch exit } if
  124.     3 copy put pop pop
  125.   } for 3 -1 roll pop exch
  126. } bind def
  127.  
  128. /.sethalftone6 {    % <dict> <dict> .sethalftone6 <setdict> <dict5>
  129.             %   { .sethalftone5 }
  130.             % Keys: Width, Height, Thresholds, T'Function
  131.   dup /Thresholds get
  132.   1 index /Width get 2 index /Height get
  133.   null 8 .makehalftone7
  134. } bind def
  135.  
  136. /.sethalftone10 {    % <dict> <dict> .sethalftone10 <setdict> <dict5>
  137.             %   { .sethalftone5 }
  138.             % Keys: Xsquare, Ysquare, Thresholds, T'Function
  139.         % Note that this is the only one of these three HalftoneTypes
  140.         % that allows either a file or a string for Thresholds.
  141.   dup /Thresholds get dup type /stringtype eq { 0 () .subfiledecode } if
  142.   1 index /Xsquare get dup 3 index /Ysquare get dup
  143.   8 .makehalftone7
  144. } bind def
  145.  
  146. /.sethalftone16 {    % <dict> <dict> .sethalftone16 <setdict> <dict5>
  147.             %   { .sethalftone5 }
  148.             % Keys: Width, Height, Width2, Height2,
  149.             %   Thresholds, T'Function
  150.   dup /Thresholds get
  151.   1 index /Width get 2 index /Height get
  152.   3 index /Width2 .knownget {  % 2-rectangle case
  153.     4 index /Height2 get
  154.   } {            % 1-rectangle case
  155.     null
  156.   } ifelse 16 .makehalftone7
  157. } bind def
  158.  
  159. .halftonetypes begin
  160.   6 /.sethalftone6 load def
  161.   10 /.sethalftone10 load def
  162.   16 /.sethalftone16 load def
  163. end
  164.  
  165. % Redefine the halftone-setting operators to honor HalftoneMode.
  166. /setcolorscreen {
  167.   /HalftoneMode getuserparam 0 eq {
  168.     //setcolorscreen
  169.   } {
  170.     12 { pop } repeat .getdefaulthalftone
  171.     { //sethalftone }
  172.     { .setdefaulthalftone }
  173.     ifelse
  174.   } ifelse
  175. } odef
  176. /setscreen {
  177.   /HalftoneMode getuserparam 0 eq {
  178.     //setscreen
  179.   } {
  180.     pop pop pop .getdefaulthalftone
  181.     { //sethalftone }
  182.     { .setdefaulthalftone }
  183.     ifelse
  184.   } ifelse
  185. } odef
  186. /sethalftone {
  187.   /HalftoneMode getuserparam 0 eq {
  188.     //sethalftone
  189.   } {
  190.     gsave //sethalftone grestore
  191.     .getdefaulthalftone
  192.     { //sethalftone }
  193.     { .setdefaulthalftone }
  194.     ifelse
  195.   } ifelse
  196. } odef
  197.  
  198. % ------ ImageTypes 3 and 4 (masked images) ------ %
  199.  
  200. .imagetypes
  201.   dup 3 /.image3 load put
  202.   dup 4 /.image4 load put
  203. % We also detect ImageType 103 here: it isn't worth making a separate file
  204. % just for this.
  205.   /.image3x where { pop dup 103 /.image3x load put } if
  206. pop
  207.  
  208. % ------ Functions ------ %
  209.  
  210. % Define the FunctionType resource category.
  211. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  212.   /InstanceType /integertype def
  213. /FunctionType currentdict end /Category defineresource pop
  214.  
  215. {0 2 3} { dup /FunctionType defineresource pop } forall
  216.  
  217. % ------ Smooth shading ------ %
  218.  
  219. % Define the ShadingType resource category.
  220. /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  221.   /InstanceType /integertype def
  222. /ShadingType currentdict end /Category defineresource pop
  223.  
  224. systemdict /.shadingtypes mark        % not ll3dict
  225.   1 /.buildshading1 load
  226.   2 /.buildshading2 load
  227.   3 /.buildshading3 load
  228.   4 /.buildshading4 load
  229.   5 /.buildshading5 load
  230.   6 /.buildshading6 load
  231.   7 /.buildshading7 load
  232. .dicttomark put
  233.  
  234. systemdict /.reuseparamdict mark
  235.   /Intent 2
  236.   /AsyncRead false
  237.   /CloseSource true
  238. .dicttomark readonly put
  239. /.buildshading {    % <shadingdict> .buildshading <shading>
  240.   dup rcheck not {
  241.       % Adobe seems to access ColorSpace first and CET 12-14c checks this.
  242.       /$error .systemvar /errorinfo [ /ColorSpace null ] put
  243.       /shfill .systemvar /invalidaccess signalerror
  244.   } if
  245.         % Unfortunately, we always need to make the DataSource reusable,
  246.         % because if clipping is involved, even shfill may need to read
  247.         % the source data multiple times.  If it weren't for this,
  248.         % we would only need to create a reusable stream if the ultimate
  249.         % source of the data is a procedure (since the library can't
  250.         % suspend shading to do a procedure callout).
  251.   dup /DataSource .knownget {
  252.     dup type /filetype eq {
  253.       //.reuseparamdict /ReusableStreamDecode filter
  254.       % Copy the dictionary to replace the DataSource, but make sure the
  255.       % copy is in the same VM as the original.
  256.       .currentglobal 2 index gcheck .setglobal
  257.         % Stack: shdict rsdfile saveglobal
  258.       2 index dup length dict copy exch .setglobal
  259.       dup /DataSource 4 -1 roll put exch pop
  260.     } {
  261.       pop
  262.     } ifelse
  263.   } if
  264.     % The .buildshading operators use the current color space
  265.     % for ColorSpace.
  266.   dup /ShadingType .knownget not { % error handling for CET 12-14b conformance
  267.      /$error .systemvar /errorinfo [ /ShadingType //null ] put
  268.      /shfill .systemvar /undefined signalerror
  269.   } if
  270.   dup type /integertype ne {
  271.      /$error .systemvar /errorinfo [ /ShadingType 4 index ] put
  272.      /shfill .systemvar /typecheck signalerror
  273.   } if
  274.   //.shadingtypes 1 index .knownget not {
  275.      /$error .systemvar /errorinfo [ /ShadingType 4 index ] put
  276.      /shfill .systemvar /rangecheck signalerror
  277.   } if
  278.   exch pop 1 index /ColorSpace .knownget {
  279.     { setcolorspace } stopped {
  280.        /$error .systemvar /errorinfo [ /ColorSpace 4 index ] put
  281.        /shfill .systemvar /$error .systemvar /errorname get signalerror
  282.     } if
  283.     exec
  284.   } { 
  285.     /$error .systemvar /errorinfo [ /ColorSpace //null ] put
  286.     /shfill .systemvar /undefined signalerror
  287.   } ifelse
  288. } bind def
  289. systemdict /.reuseparamdict undef
  290.  
  291. /.buildpattern2 {    % <template> <matrix> .buildpattern2
  292.             %   <template> <pattern>
  293.     % We want to build the pattern without doing gsave/grestore,
  294.     % since we want it to load the CIE caches.
  295.   1 index /Shading get
  296.   mark currentcolor currentcolorspace
  297.   counttomark 4 add -3 roll mark 4 1 roll
  298.     % Stack: -mark- ..color.. cspace -mark- template matrix shadingdict
  299.   { .buildshading } stopped {
  300.     cleartomark setcolorspace setcolor pop stop
  301.   } if
  302.   .buildshadingpattern
  303.   3 -1 roll pop counttomark 1 add 2 roll setcolorspace setcolor pop
  304. } bind def
  305.  
  306. .patterntypes
  307.   2 /.buildpattern2 load put
  308.  
  309. /shfill {        % <shadingdict> shfill -
  310.     % Currently, .shfill requires that the color space
  311.     % in the pattern be the current color space.
  312.     % Disable overprintmode for shfill
  313.   { dup gsave 0 .setoverprintmode .buildshading .shfill } stopped
  314.   grestore {
  315.     /$error .systemvar /errorinfo 2 copy known {
  316.       pop pop
  317.     } {
  318.       //null put  % CET 12-14c
  319.     } ifelse
  320.     stop
  321.   } if
  322.   pop
  323. } odef
  324.  
  325. % Establish an initial smoothness value that matches Adobe RIPs.
  326. 0.02 setsmoothness
  327.  
  328. % ------ DeviceN color space ------ %
  329. % gs_res.ps uses these entries in colorspacedict
  330. % to populate the ColorSpaceFamily resource, so we need
  331. % to add the supported spaces.
  332. %
  333. systemdict /colorspacedict get begin
  334. /CIEBasedDEF [] def
  335. /CIEBasedDEFG [] def
  336. /DeviceN [] def
  337. end
  338.  
  339. % ------ Miscellaneous ------ %
  340.  
  341. % Make the setoverprintmode and currentoverprintmode operators visible (3015)
  342. % Because of the requirements of PDF, the .currentoverprintmode and
  343. % .setoverprintmode operators have integer parameters.  Thus we need to
  344. % convert the Postscript bool parameters to integers.
  345. %
  346. /setoverprintmode         % bool setoverprint -
  347. {
  348.   { 1 } { 0 } ifelse        % convert bool to integer
  349.   //.setoverprintmode
  350. } odef
  351.  
  352. /currentoverprintmode         % - currentoverprintmode bool
  353. {
  354.   //.currentoverprintmode
  355.   0 ne                % convert integers to bool
  356. } odef
  357.  
  358. % Define additional user and system parameters.
  359. /HalftoneMode 0 .definepsuserparam
  360. /MaxSuperScreen 1016 .definepsuserparam
  361. pssystemparams begin        % read-only, so use .forcedef
  362.   /MaxDisplayAndSourceList 160000 .forcedef
  363. end
  364.  
  365. % Define the IdiomSet resource category.
  366. { /IdiomSet } {
  367.   /Generic /Category findresource dup maxlength 3 add dict .copydict begin
  368.     /InstanceType /dicttype def
  369.   currentdict end /Category defineresource pop
  370. } forall
  371.  
  372. /languagelevel 3 def
  373. % When running in LanguageLevel 3 mode, this interpreter is supposed to be
  374. % compatible with Adobe version 3010.
  375. /version (3010) readonly def
  376.  
  377. .setlanguagelevel
  378.  
  379. end            % ll3dict
  380.